package com.cms.util;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Formater {

    public static SimpleDateFormat dateTimeFormater = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss", Locale.US);
    public static SimpleDateFormat dateTimeFormater2 = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm", Locale.US);
	
    public static String formatDateTime(Date dt) {
        if (dt == null)
            return "";
        else{
            return dateTimeFormater.format(dt);
        }
    }

    public static String formatDateSimpleTime(Date dt) {
        if (dt == null)
            return "";
        else{
            return dateTimeFormater2.format(dt);
        }
    }
    
    public static String formatDateSimpleTime(Timestamp dt) {
        if (dt == null)
            return "";
        else{
            return dateTimeFormater2.format(dt);
        }
    }
    
    public static String getParam(String param, String defaultStr) {
        if (StringHelper.isEmpty(param)) {
           return defaultStr;
       } else {
           return param;
       }
   }
	
    public static String filterFileName(String fileName) {
        String str = fileName;
        if (!StringHelper.isEmpty(fileName)) {
            str = str.replace(' ', '_');
            str = str.replace('·', '.');
            str = str.replace('#', '_');
            str = str.replace('&', '_');
            str = str.replace('$', '_');
            str = str.replace('@', '_');
            str = str.replace('\uFF08', '(');
            str = str.replace('\uFF09', ')');
        }
        return str;
    }
    
    public static String formatText(String in) {
        if (in == null)
            return "";
        else{
            in = in.replace("\"","&#34;");
            return in;
        }
    }
}
